package com.wiscamp.ninechapters.panels.infrastructure.mappers;

import com.wiscamp.ninechapters.panels.infrastructure.views.ParameterView;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;

import java.util.Collection;

@Component
public interface ParameterViewMapper extends JpaRepository<ParameterView, Long>, JpaSpecificationExecutor<ParameterView> {

    @Query(value = "select p from ParameterView p where p.applicationId = :appId and p.parameterCode = :parameterCode")
    ParameterView findByParameterCode(long appId, String parameterCode);

    @Query(value = "select p from ParameterView p where p.applicationId = :appId and p.parameterName = :parameterName")
    Collection<ParameterView> findListByParameterName(long appId, String parameterName);

    @Query(value = "select p from ParameterView p where p.applicationId = :appId and p.parameterGroup = :parameterGroup")
    Collection<ParameterView> findListByParameterGroup(long appId, String parameterGroup);

    Page<ParameterView> findAll(Specification<ParameterView> specification, Pageable pageable);
}
